package com.immo.libcommon.base;

import android.support.v4.app.Fragment;

import static com.immo.libcommon.utils.ToastUtils.showToast;

/**
 * @author Administrator
 * @content Fragment基类
 * @date 2017/11/10
 */

public abstract class BaseFragment extends Fragment {
    protected boolean isVisible;

    /**
     * 在这里实现Fragment数据的缓加载.
     *
     * @param isVisibleToUser 是否可见
     */
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        isVisible = getUserVisibleHint();
        if (getUserVisibleHint()) {
            onVisible();
        } else {
            onInvisible();
        }
    }

    protected void onVisible() {
        lazyLoad();
    }

    protected abstract void lazyLoad();

    protected void onInvisible() {
    }

    public void toast(String content) {
        showToast(getActivity(), content);
    }

}
